import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/monster/monsterSupplierCostSubmit/list',
  save='/monster/monsterSupplierCostSubmit/add',
  edit='/monster/monsterSupplierCostSubmit/edit',
  deleteOne = '/monster/monsterSupplierCostSubmit/delete',
  deleteBatch = '/monster/monsterSupplierCostSubmit/deleteBatch',
  importExcel = '/monster/monsterSupplierCostSubmit/importExcel',
  exportXls = '/monster/monsterSupplierCostSubmit/exportXls',
  queryCurrentCostBudget ='/monster/monsterSubmitApply/queryCurrentCostBudget',
  // 送审
  sendProjectSubmitApply='/monster/monsterSubmitApply/sendProjectSubmitApply',
  // 审核
  costApply='/monster/monsterSubmitApply/costApply',
  // 人员信息
  queryStaffBySubmitId='/monster/monsterProejctStaff/queryStaffBySubmitId',
  SipplierPaymentModule='/monster/monsterSupplierCostSubmit/SipplierPaymentModule'

}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});

export const queryStaffBySubmitId = (params) =>
defHttp.get({url: Api.queryStaffBySubmitId, params});

  /**
 * 预算列表
 * @param params
 */
export const queryCurrentCostBudget = (params) =>
defHttp.get({url: Api.queryCurrentCostBudget, params});

export const SipplierPaymentModule = (params) =>
defHttp.get({url: Api.SipplierPaymentModule, params});



/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.get({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.get({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess()
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}

export const sendProjectSubmitApply = (params) => {
  return defHttp.post({url: Api.sendProjectSubmitApply, params});
}

export const costApply = (params, handleSuccess) => {
  let comfirmResult = '';
  if (params.applyStatus == 1){
    comfirmResult = '是否确认审核通过！'
  }else {
    comfirmResult = '是否确认拒绝！'
  }
  createConfirm({
    iconType: 'warning',
    title: '审核确认',
    content: comfirmResult,
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.post({url: Api.costApply, params}).then(() => {
        handleSuccess()
      });
    }
  });
}
